<template>
  <div class="swiper_wrap">
    <Swipe class="my-swiper" :autoplay="5000" v-if="list.length > 0" @change="swiperChange">
      <SwipeItem v-for="(item, index) in list" :key="index">
        <a :href="item.url" v-if="item.url">
          <img :src="item.covers"  />
        </a>
        <img v-else :src="item.covers"  />
      </SwipeItem>
    </Swipe>
    <div class="default_img" v-else>
      <img src="@assets/img/empty.jpg" />
    </div>
  </div>
</template>

<script> 
import { Swipe, SwipeItem } from "vant";
export default {
  name: "pageBanner",
  data(){
    return{
      list:[
        {
          covers:'https://img1.baidu.com/it/u=73351948,1502173098&fm=26&fmt=auto&gp=0.jpg',
          url:''
        },
        {
          covers:'https://img0.baidu.com/it/u=1735125246,848408634&fm=26&fmt=auto&gp=0.jpg',
          url:''
        },  
        {
          covers:'https://img0.baidu.com/it/u=2503764337,3561941724&fm=26&fmt=auto&gp=0.jpg',
          url:''
        }
      ]
    }
  },
  components: { Swipe, SwipeItem },
  created(){
    this.$emit("bannerChange", this.list[0].covers);
  },
  computed: {
    swiper() {
      return this.$refs.mySwiper.$swiper;
    },
  }, 
  methods: {
    swiperChange(e) {
      this.$emit("bannerChange", this.list[e].covers);
    },
  }, 
};
</script>

<style scoped lang="scss">
.swiper_wrap {
  height: 3.64rem;
  .default_img {
    margin: 0 10px;
    border-radius: 5px;
    height: 3.8rem;
    img {
      border-radius: 5px;
      display: block;
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  }
}
.my-swiper {
  height: 100%;
  margin: 0.2rem 0.2rem 0;
  border-radius: 5px;
  img {
    border-radius: 5px;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}
.swiper-container {
  font-size: 0;
}
.swiper-slide {
  position: relative;
  width: 100%;
  height: 100%;
  display: block;
}
.swiper-tool {
  height: 0.52rem;
  display: flex;
  align-items: center;
  background-color: rgba(#000, 0.35);
  border-radius: 13px 0 0 13px;
  padding: 0 0.3rem;
  font-size: 0.2rem;
  color: #fff;
  position: absolute;
  top: 0.21rem;
  right: 0;
}
</style>
